package com.growthsee.rider.wrapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.growthsee.rider.domain.RiderQuestionType;
import com.growthsee.rider.enumeration.YesNoEnum;
import com.growthsee.rider.mapper.RiderQuestionTypeMapper;
import com.growthsee.rider.utils.ApplicationContexts;
import org.apache.commons.lang3.StringUtils;

/**
 * @author ycj
 * @Description: 评价活动视图包装类
 * @date 2020/05/24
 **/
public class QuestionTypeWrapper {


    public static QuestionTypeWrapper builder() {
        return new QuestionTypeWrapper();
    }



    public String check(RiderQuestionType riderQuestionType){
        RiderQuestionTypeMapper riderQuestionTypeMapper = ApplicationContexts.getBean(RiderQuestionTypeMapper.class);
        LambdaQueryWrapper<RiderQuestionType> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(RiderQuestionType::getDeleted, YesNoEnum.NO.getValue());
        if(StringUtils.isNotEmpty(riderQuestionType.getName())){
            queryWrapper.eq(RiderQuestionType::getName,riderQuestionType.getName());
        }
        if(StringUtils.isNotEmpty(riderQuestionType.getId())){
            queryWrapper.ne(RiderQuestionType::getId,riderQuestionType.getId());
        }
        Integer integer = riderQuestionTypeMapper.selectCount(queryWrapper);
        if(integer>0){
            return "题型已存在";
        }else return "";
    }

}
